<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:x="http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key">

  <xsl:output method="xml" version="1.0" omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>

  <xsl:include href="include/Slices.xslt"/>

  <xsl:template name="ImpedimentList">
    <xsl:param name="list" />
    <xsl:param name="solved" />

    <Table Style="{{StaticResource NoBorderTable}}">

      <Table.Columns>
        <TableColumn Width="40" />
        <TableColumn Width="40" />
        <TableColumn />
        <TableColumn Width="100" />
        <xsl:if test="$solved">
          <TableColumn Width="100" />
        </xsl:if>
      </Table.Columns>

      <TableRowGroup>

        <TableRow>
          <TableCell Style="{{StaticResource DoubleLineCell}}" TextAlignment="Right">
            <Paragraph>
              <Bold>#</Bold>
            </Paragraph>
          </TableCell>
          <TableCell Style="{{StaticResource DoubleLineCell}}"  TextAlignment="Right">
            <Paragraph>
              <Bold>Date</Bold>
            </Paragraph>
          </TableCell>
          <TableCell Style="{{StaticResource DoubleLineCell}}">
            <Paragraph TextAlignment="Left">
              <Bold>Impediment</Bold>
            </Paragraph>
          </TableCell>
          <xsl:if test="not($solved)">
            <TableCell Style="{{StaticResource DoubleLineCell}}">
              <Paragraph TextAlignment="Left">
                <Bold>Who is solving</Bold>
              </Paragraph>
            </TableCell>
          </xsl:if>
          <xsl:if test="$solved">
            <TableCell Style="{{StaticResource DoubleLineCell}}">
              <Paragraph TextAlignment="Left">
                <Bold>Solved at</Bold>
              </Paragraph>
            </TableCell>

            <TableCell Style="{{StaticResource DoubleLineCell}}">
              <Paragraph TextAlignment="Left">
                <Bold>Solved by</Bold>
              </Paragraph>
            </TableCell>
          </xsl:if>

        </TableRow>

        <xsl:for-each select="$list">
          <xsl:sort select="Finish" order="descending" />
          <xsl:sort select="TaskId" data-type="number" order="descending" />

          <TableRow >
            <TableCell Style="{{StaticResource SingleLineCell}}" TextAlignment="Right">
              <Paragraph>
                <xsl:value-of select="TaskId"/>
              </Paragraph>
            </TableCell>
            <TableCell Style="{{StaticResource SingleLineCell}}"  TextAlignment="Right">
              <Paragraph>
                <xsl:value-of select="StartString"/>
              </Paragraph>
            </TableCell>
            <TableCell Style="{{StaticResource SingleLineCell}}">
              <Paragraph  FontSize="12">
                <Bold>
                  <xsl:value-of select="TaskName"/>
                </Bold>
              </Paragraph>
            </TableCell>
            <xsl:if test="$solved">
              <TableCell Style="{{StaticResource SingleLineCell}}">
                <Paragraph>
                  <xsl:value-of select="FinishString"/>
                </Paragraph>
              </TableCell>
            </xsl:if>
            <TableCell Style="{{StaticResource SingleLineCell}}">
              <Paragraph>
                <xsl:value-of select="TaskAssignee"/>
              </Paragraph>
            </TableCell>
                   
          </TableRow>


        </xsl:for-each>


      </TableRowGroup>
    </Table>

    <xsl:if test="count($list)=0">
      <Paragraph>None</Paragraph>
    </xsl:if>



  </xsl:template>

  <xsl:template match="/">

    <FlowDocument PageWidth="21cm"
      PagePadding="60,40,40,40"
      PageHeight="29.7cm"
      ColumnWidth="21 cm">

      <xsl:call-template name="StyleSettings"/>

      <xsl:call-template name="Header">
        <xsl:with-param name="type" select="'Impediment List'"/>
        <xsl:with-param name="context" select="/ProjectHourBankDataSet"/>
      </xsl:call-template>
      
      

      <Paragraph Style="{{StaticResource TitleParagraph}}">        
        Current Impediments (<xsl:value-of select="count(/ProjectHourBankDataSet/PayableTasks[TaskType=4 and Status &lt; 4])"/>)
      </Paragraph>

      <xsl:call-template name="ImpedimentList">
        <xsl:with-param name="list" select="/ProjectHourBankDataSet/PayableTasks[TaskType=4 and Status &lt; 4]"/>
      </xsl:call-template>
   
      <Paragraph Style="{{StaticResource TitleParagraph}}">
        <LineBreak/>
        Solved Impediments (<xsl:value-of select="count(/ProjectHourBankDataSet/PayableTasks[TaskType=4 and Status &gt;= 4])"/>)
      </Paragraph>

      <xsl:call-template name="ImpedimentList">
        <xsl:with-param name="list" select="/ProjectHourBankDataSet/PayableTasks[TaskType=4 and Status &gt;= 4]"/>
        <xsl:with-param name="solved" select="1"/>
      </xsl:call-template>



    </FlowDocument>

  </xsl:template>




</xsl:stylesheet>